package com.weather.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.weather.bean.ProvinceCodeBean;
import com.weather.util.DBManager;
import com.weather.util.JdbcUtil;

public class ProvinceCodeDAO {
	
	
	private static List<ProvinceCodeBean> provinceList;
	
	public static List<ProvinceCodeBean> getAll(){
		provinceList = new ArrayList<ProvinceCodeBean>();
		Connection conn = null;
		ResultSet rs = null;
		String sql = "select * from province_code_table";
		PreparedStatement pstmt = null;
	
		try {
			conn = DBManager.getConn();
			pstmt = (PreparedStatement)conn.prepareStatement(sql);
			rs = pstmt.executeQuery();
			int col = rs.getMetaData().getColumnCount();
			while(rs.next()){
				ProvinceCodeBean pcb = new ProvinceCodeBean(rs.getString("province_code"),rs.getString("province_name"));
				provinceList.add(pcb);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally{
			DBManager.cloesConn(rs, null, pstmt, conn);
		}
		
		return provinceList;
	}
}
